<template>
  <div class="article-item">
    <!-- <van-cell :to="`/article/${article.art_id}`"> -->
    <van-cell
      class="article-item"
      :to="{ name: 'article', params: { articleId: article.art_id } }"
    >
      <div slot="title">{{ article.title }}</div>
      <div slot="label">
        <div v-if="article.cover.type === 3" class="cover-wrap">
          <div
            v-for="(img, index) in article.cover.images"
            :key="index"
            class="cover-item"
          >
            <van-image
              class="cover-item-img"
              :src="img"
              @click="showPopup(img)"
            />
          </div>
        </div>
        <div>
          <span>{{ article.aut_name }}</span>
          <span>{{ article.comm_count }}评论</span>
          <span>{{ article.pubdate | relativeTime }}</span>
        </div>
      </div>

      <van-image
        v-if="article.cover.type === 1"
        slot="default"
        width="100"
        height="100"
        :src="article.cover.images[0]"
        @click="showPopup(article.cover.images[0])"
      />
    </van-cell>
    <van-popup v-model="show" closeable>
      <van-image width="100vw" :src="img" />
    </van-popup>
  </div>
</template>

<script>
export default {
  name: 'ArticleItem',
  props: {
    article: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      show: false,
      img: ''
    }
  },

  methods: {
    showPopup (img) {
      this.show = true
      this.img = img
    }
  }
}
</script>

<style lang="less" scoped>
.cover-wrap {
  display: flex;
  padding: 30px 0;
  .cover-item {
    flex: 1;
    height: 146px;
    &:not(:last-child) {
      padding-right: 4px;
    }
    .cover-item-img {
      width: 100%;
      height: 146px;
    }
  }
}
</style>
